package org.dochandler.esfinge.guardian.authorizer;

import org.dochandler.service.domain.annotation.ApplyMissionApprovePolicy;
import org.esfinge.guardian.authorizer.Authorizer;
import org.esfinge.guardian.context.AuthorizationContext;

public class ApplyMissionApprovePolicyAuthorizer implements Authorizer<ApplyMissionApprovePolicy>{

	@Override
	public Boolean authorize(AuthorizationContext context, ApplyMissionApprovePolicy securityAnnotation) {
		
		WorkingTimeAuthorizer wtAuthorizer = new WorkingTimeAuthorizer();
		MissionWithinBudgetAuthorizer mwbAuthorizer = new MissionWithinBudgetAuthorizer();
		WarMissionApprovalPolicyAuthorizer wpAuthorizer = new WarMissionApprovalPolicyAuthorizer(); 
		
		Boolean isInWorkingHour = wtAuthorizer.authorize(context, null);
		Boolean isMissionWithinBudget = mwbAuthorizer.authorize(context, null);
		Boolean isAtWar = wpAuthorizer.authorize(context, null);
		
		return (isAtWar || (isInWorkingHour && isMissionWithinBudget));
	}

}
